/*
 * Copyright (c) 2009 Albert Kurucz. 
 *
 * This file, TestStepSelectPanel.java is part of JTStand.
 *
 * JTStand is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JTStand is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with GTStand.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.jtstand.swing;

import com.jtstand.TestStepInstance;
import com.jtstand.TestStepNamePath;

/**
 *
 * @author  albert_kurucz
 */
public class TestStepSelectPanel extends javax.swing.JPanel {

    public static final long serialVersionUID = 20081114L;

    /** Creates new form TestStepPanel */
    public TestStepSelectPanel() {
        initComponents();
    }

    public void selectStep(TestStepInstance step) {
        if (step != null) {
            TestStepNamePath tsnp = step.getTestStepNamePath();
            if (tsnp != null) {
                jTextFieldTestStepName.setText(tsnp.getStepName());
                jTextFieldTestStepPath.setText(tsnp.getStepPath());
            }
        }
    }

    public String toString(String q, String base) {
        if (jTextFieldTestStepName.isEditable() && jTextFieldTestStepName.getText().length() > 0) {
            q = QueryDialog.add(q, base + "testStepNamePath.stepName = '" + jTextFieldTestStepName.getText() + "'");
        } else if (jTextFieldTestStepPath.isEditable() && jTextFieldTestStepPath.getText().length() > 0) {
            q = QueryDialog.add(q, base + "testStepNamePath.stepPath = '" + jTextFieldTestStepPath.getText() + "'");
        }
        return q;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupTestStep = new javax.swing.ButtonGroup();
        jPanel14 = new javax.swing.JPanel();
        jRadioButtonName = new javax.swing.JRadioButton();
        jPanel31 = new javax.swing.JPanel();
        jTextFieldTestStepName = new javax.swing.JTextField();
        jPanel32 = new javax.swing.JPanel();
        jPanel22 = new javax.swing.JPanel();
        jPanel15 = new javax.swing.JPanel();
        jRadioButtonPath = new javax.swing.JRadioButton();
        jPanel33 = new javax.swing.JPanel();
        jTextFieldTestStepPath = new javax.swing.JTextField();
        jPanel34 = new javax.swing.JPanel();
        jPanel23 = new javax.swing.JPanel();

        setBorder(javax.swing.BorderFactory.createTitledBorder("Test Step"));
        addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                formFocusGained(evt);
            }
        });
        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));

        jPanel14.setLayout(new javax.swing.BoxLayout(jPanel14, javax.swing.BoxLayout.LINE_AXIS));

        buttonGroupTestStep.add(jRadioButtonName);
        jRadioButtonName.setMnemonic('N');
        jRadioButtonName.setText("Name:");
        jRadioButtonName.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jRadioButtonName.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jRadioButtonName.setPreferredSize(new java.awt.Dimension(90, 23));
        jRadioButtonName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonNameActionPerformed(evt);
            }
        });
        jPanel14.add(jRadioButtonName);

        jPanel31.setMaximumSize(new java.awt.Dimension(5, 5));
        jPanel31.setMinimumSize(new java.awt.Dimension(5, 5));
        jPanel31.setPreferredSize(new java.awt.Dimension(5, 5));
        jPanel14.add(jPanel31);

        jTextFieldTestStepName.setEditable(false);
        jPanel14.add(jTextFieldTestStepName);

        jPanel32.setMaximumSize(new java.awt.Dimension(5, 5));
        jPanel32.setMinimumSize(new java.awt.Dimension(5, 5));
        jPanel32.setPreferredSize(new java.awt.Dimension(5, 5));
        jPanel14.add(jPanel32);

        add(jPanel14);

        jPanel22.setMaximumSize(new java.awt.Dimension(5, 5));
        jPanel22.setMinimumSize(new java.awt.Dimension(5, 5));
        jPanel22.setPreferredSize(new java.awt.Dimension(5, 5));
        add(jPanel22);

        jPanel15.setLayout(new javax.swing.BoxLayout(jPanel15, javax.swing.BoxLayout.LINE_AXIS));

        buttonGroupTestStep.add(jRadioButtonPath);
        jRadioButtonPath.setMnemonic('P');
        jRadioButtonPath.setSelected(true);
        jRadioButtonPath.setText("Path:");
        jRadioButtonPath.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jRadioButtonPath.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jRadioButtonPath.setPreferredSize(new java.awt.Dimension(90, 23));
        jRadioButtonPath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonPathActionPerformed(evt);
            }
        });
        jPanel15.add(jRadioButtonPath);

        jPanel33.setMaximumSize(new java.awt.Dimension(5, 5));
        jPanel33.setMinimumSize(new java.awt.Dimension(5, 5));
        jPanel33.setPreferredSize(new java.awt.Dimension(5, 5));
        jPanel15.add(jPanel33);
        jPanel15.add(jTextFieldTestStepPath);

        jPanel34.setMaximumSize(new java.awt.Dimension(5, 5));
        jPanel34.setMinimumSize(new java.awt.Dimension(5, 5));
        jPanel34.setPreferredSize(new java.awt.Dimension(5, 5));
        jPanel15.add(jPanel34);

        add(jPanel15);

        jPanel23.setMaximumSize(new java.awt.Dimension(5, 5));
        jPanel23.setMinimumSize(new java.awt.Dimension(5, 5));
        jPanel23.setPreferredSize(new java.awt.Dimension(5, 5));
        add(jPanel23);
    }// </editor-fold>//GEN-END:initComponents

private void jRadioButtonPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonPathActionPerformed
    this.jTextFieldTestStepName.setEditable(false);
    this.jTextFieldTestStepPath.setEditable(true);
}//GEN-LAST:event_jRadioButtonPathActionPerformed

private void jRadioButtonNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonNameActionPerformed
    this.jTextFieldTestStepPath.setEditable(false);
    this.jTextFieldTestStepName.setEditable(true);
}//GEN-LAST:event_jRadioButtonNameActionPerformed

private void formFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusGained
    if (jTextFieldTestStepName.isEditable()) {
        jTextFieldTestStepName.requestFocus();
    } else if (jTextFieldTestStepPath.isEditable()) {
        jTextFieldTestStepPath.requestFocus();
    }
}//GEN-LAST:event_formFocusGained
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupTestStep;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel22;
    private javax.swing.JPanel jPanel23;
    private javax.swing.JPanel jPanel31;
    private javax.swing.JPanel jPanel32;
    private javax.swing.JPanel jPanel33;
    private javax.swing.JPanel jPanel34;
    private javax.swing.JRadioButton jRadioButtonName;
    private javax.swing.JRadioButton jRadioButtonPath;
    private javax.swing.JTextField jTextFieldTestStepName;
    private javax.swing.JTextField jTextFieldTestStepPath;
    // End of variables declaration//GEN-END:variables
}
